﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using HK2009.BusinessFacade;
using HK2009.EntityManage;
using HK2009.Common;
using HK2009.EntityQuery;

namespace HK2009.BusinessFacadeHandler
{
    public class BNTruckHandler : IBNTruckHandler
    {
        DataBase db = new DataBase();
        BN_TruckManage manager = new BN_TruckManage();

        /// <summary>
        /// 根据sql语句同参数获取列表
        /// </summary>
        /// <param name="sqlStr"></param>
        /// <param name="parms"></param>
        /// <returns></returns>
        public DataTable GetList(string sqlStr, SqlParameter[] parms)
        {
            return db.RunSqlTab(sqlStr, parms);
        }


        /// <summary>
        /// 根据ID删除记录
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        public bool DeleteByID(int pkid)
        {
            return manager.DeleteBN_Truck(pkid);
        }


        /// <summary>
        /// 根据ID获取
        /// </summary>
        /// <param name="pkid"></param>
        /// <returns></returns>
        public BN_TruckQuery GetTruckByID(int pkid)
        {
            return manager.GetBN_TruckQuery(pkid);
        }


        /// <summary>
        ///  更改
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public bool UpdateTruck(BN_TruckQuery query)
        {
            return manager.UpdateBN_Truck(query);
        }


        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public bool AddTruck(BN_TruckQuery query)
        {
            return manager.InsertBN_Truck(query);
        }

        public bool AddTruck(BN_TruckQuery query, ref int pkid)
        {
            return manager.InsertBN_Truck(query, ref pkid);
        }

        /// <summary>
        /// 根据客户获取属于该客户的所有车辆
        /// </summary>
        /// <param name="clientID"></param>
        /// <returns></returns>
        public DataTable GetTruckList(int clientID)
        {
            SqlParameter[] parms = new SqlParameter[2];
            parms[0] = new SqlParameter("@ClientID",clientID.ToString());
            parms[1] = new SqlParameter("@Status","1");
            return manager.GetBN_TruckList(" ClientID=@ClientID and Status=@Status",parms);
        }
     
    }
}